<?php

// Last Modified: $Id: output_fns.php 217 2005-10-01 19:48:33Z foz $

function do_html_header($title ="UNY-Con: Upstate New York's Premiere Gaming convention", $size ="staysmall", $uny)
{
  //Print HTML header
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title><?php echo $title;?></title>
	<meta name="generator" content="BBEdit" />
	<link rel="StyleSheet" rev="Stylesheet" href="http://loki.local/~plummer/uny-con/uny.css" type="text/css" media="screen" charset="iso-8859-1" />
	<link rel="StyleSheet" rev="Stylesheet" href="http://loki.local/~plummer/uny-con/print.css" type="text/css" media="print" charset="iso-8859-1" />
	<link rel="icon" href="http://loki.local/~plummer/uny-con/favicon.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="http://loki.local/~plummer/uny-con/favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="header">
	<? include "/home/domains/uny-con.com/public_html/includes/header.php" ?>
</div>
<div class="menu">
	<? display_menu($uny) ?>
</div>
<div id="quickfacts">
	<? include "/home/domains/uny-con.com/public_html/includes/quickfacts.php" ?>
</div>
<div id="millennium">
	<? include "/home/domains/uny-con.com/public_html/includes/millennium.php" ?>
</div>
<div class="contact">
	<? include "/home/domains/uny-con.com/public_html/includes/contact.php" ?>
</div>
<div class="loginbar">
	<? include "/home/domains/uny-con.com/public_html/includes/loginbar.php" ?>
</div>
<? if ($size == 'staysmall') { echo '<div class="content">';}
	elseif ($size == 'gobig') { echo '<div class="content2">';}
?>

	
<?php

}

function print_nav_menu_item($active, $name, $title, $url) {

	$link = "<a href=\"$url\" title=\"$title\">";
	if ($active == "active") {
		echo "$link"; ?>
		<span class="active">
		<img class="menuleft" src="http://loki.local/~plummer/uny-con/images/littleleftedgewt.jpg" alt="" />
		<h3><? echo "$name" ; ?></h3>
		<img class="menuright" src="http://loki.local/~plummer/uny-con/images/littlerightedgewt.jpg" alt="" />
		</span></a>
		<?
		}
	else {
		echo "$link"; ?>
		<span class="inactive">
		<img class="menuleft" src="http://loki.local/~plummer/uny-con/images/littleleftedge.jpg" alt="" />
		<h1><? echo "$name" ; ?></h1>
		<img class="menuright" src="http://loki.local/~plummer/uny-con/images/littlerightedge.jpg" alt="" />
		</span></a>
		<?
		}
}

function display_menu($uny)
{

$base_path = 'http://loki.local/~plummer/uny-con/';

$page_1 = "index.php?uny=home.php";
$title_1 = "The UNY-Con home page.";
$name_1 = "UNY-Con Home";
$page_2 = "index.php?uny=info.php";
$title_2 = "UNY-Con info including general, travel, GM, and volunteer info.";
$name_2 = "Convention Info";
$page_3 = "index.php?uny=featured_events.php";
$title_3 = "Information on UNY-Con's featured events.";
$name_3 = "Featured Events";
$page_4 = "index.php?uny=featuredguests.php";
$title_4 = "Information UNY-Con's featured guests.";
$name_4 = "Featured Guests";
$page_5 = "index.php?uny=info.php#travel";
$title_5 = "Information about getting to and staying at UNY-Con.";
$name_5 = "Travel & Lodging";
$page_6 = "registration/event_list.php";
$title_6 = "See the exciting events at UNY-Con and sign up to play or GM.";
$name_6 = "Event List";
if (check_valid_user()) 
	{
	$page_7 = "registration/attendee_home.php";
	$title_7 = "View and manage your UNY-Con schedule.";
	$name_7 = "View My Schedule";
	$page_8 = "registration/submit_event.php";
	$title_8 = "Submit an event for UNY-Con.";
	$name_8 = "Submit Event";
	if (!get_con_attendance_status($_SESSION['current_attendee_id'])) {
		$page_9 = "registration/register_for_con.php";
		$title_9 = "Register for UNY-Con.";
		$name_9 = "Register For Con";
		} else {
		$page_9 = "registration/event_list.php";
		$title_9 = "Sign up for events";
		$name_9 = "Event Signup";
		}
	if ($_SESSION['admin'] == 't') {
		$page_10 = "registration/admin_home.php";
		$title_10 = "Admin home page.";
		$name_10 = "Admin Home";
		} else {
		$page_10 = "registration/manage_gms.php";
		$title_10 = "Manage Co-GMs";
		$name_10 = "Manage Co-GMs";
		}
	if ($_SESSION['admin'] == 't') {
		$page_11 = "registration/register_form.php?admin_add_user=Y";
		$title_11 = "Administrative add user page.";
		$name_11 = "Admin Add User";
		}
	}

$menu_item_1 = array("name" => "$name_1", "title" => "$title_1", "url" => "$base_path$page_1", "page" => "$page_1");
$menu_item_2 = array("name" => "$name_2", "title" => "$title_2", "url" => "$base_path$page_2", "page" => "$page_2");
$menu_item_3 = array("name" => "$name_3", "title" => "$title_3", "url" => "$base_path$page_3", "page" => "$page_3");
$menu_item_4 = array("name" => "$name_4", "title" => "$title_4", "url" => "$base_path$page_4", "page" => "$page_4");
$menu_item_5 = array("name" => "$name_5", "title" => "$title_5", "url" => "$base_path$page_5", "page" => "$page_5");
$menu_item_6 = array("name" => "$name_6", "title" => "$title_6", "url" => "$base_path$page_6", "page" => "$page_6");
if((isset($name_7)) && (isset($title_7)) && (isset($page_7)))
{
$menu_item_7 = array("name" => "$name_7", "title" => "$title_7", "url" => "$base_path$page_7", "page" => "$page_7");
}
if((isset($name_8)) && (isset($title_8)) && (isset($page_8)))
{
$menu_item_8 = array("name" => "$name_8", "title" => "$title_8", "url" => "$base_path$page_8", "page" => "$page_8");
}
if((isset($name_9)) && (isset($title_9)) && (isset($page_9)))
{
$menu_item_9 = array("name" => "$name_9", "title" => "$title_9", "url" => "$base_path$page_9", "page" => "$page_9");
}
if((isset($name_10)) && (isset($title_10)) && (isset($page_10)))
{
$menu_item_10 = array("name" => "$name_10", "title" => "$title_10", "url" => "$base_path$page_10", "page" => "$page_10");
}
if((isset($name_11)) && (isset($title_11)) && (isset($page_11)))
{
$menu_item_11 = array("name" => "$name_11", "title" => "$title_11", "url" => "$base_path$page_11", "page" => "$page_11");
}
	
$nav_menu_items = array($menu_item_1, $menu_item_2, $menu_item_3, $menu_item_4, $menu_item_5, $menu_item_6);
if (check_valid_user()) {
	$nav_menu_items[] = $menu_item_7;
	$nav_menu_items[] = $menu_item_8;
	$nav_menu_items[] = $menu_item_9;
	$nav_menu_items[] = $menu_item_10;
	}
if (isset($_SESSION['admin']))
	{
	if ($_SESSION['admin'] == 't') { $nav_menu_items[] = $menu_item_11; }
	}
foreach ($nav_menu_items as $row) {
	$active = 'inactive';
	if (strpos($_SERVER['REQUEST_URI'], $row['page'])) $active = active;
	print_nav_menu_item($active, $row['name'], $row['title'], $row['url']);
	}
	if (!check_valid_user()) {
		echo '<img src="http://loki.local/~plummer/uny-con/images/unyconbluehead.jpg" alt="UNY-Con Head" />';
		}

}

function do_html_footer($print_news = "news")
{
  // print an HTML footer.
?>
<br /><br />
</div>
	<? if ($print_news == 'news') { echo '<div class="news">'; include '/home/domains/uny-con.com/public_html/includes/news.php'; echo '</div>';}
	elseif ($print_news == 'no_news') {} ?>

		<!--Fix the stupid IE 6 FLoat Bug -->
		<div style="clear:both;"></div>
	</body>
	</html>
<?php
}

function print_brs($number) {
	$i = 0;
	for ( ;$i <= $number ; $i++) {
		echo "<br />\n";
		}
}

function display_login_form()
{
?>
  <br /><br />
  <p>You must have an account to login. <a href="register_form.php">Create one now</a> or:</p>
  <form method=post action="login.php">
  <table>
   <tr>
     <td colspan=2>Log in here</td>
   <tr>
     <td>Username:</td>
     <td><input type=text name=username></td></tr>
   <tr>
     <td>Password:</td>
     <td><input type=password name=password></td></tr>
   <tr>
     <td colspan=2 align=center>
     <input type=submit value="Log in"></td></tr>
   <tr>
     <td colspan=2><a href="forgot_form.php">Forgot your password?</a></td>
   </tr>
 </table></form>
<?php
}

function change_password_form($values) {
?>
  <br><br>
  <form method=post action="<? echo $_SERVER['PHP_SELF'] ?>">
  <table>
   <tr>
     <td colspan=2>Change Password</td>
<?php	if ($_SESSION['admin'] != 't' || $_SESSION['attendee_id'] == $_SESSION['current_attendee_id']) {
   echo "<tr>
     <td>Old Password:</td>
     <td><input type=password name=current_pass></td></tr>" ;
   }
   ?>
   <tr>
     <td>New Password:</td>
     <td><input type=password name=new_pass></td></tr>
   <tr>
     <td>Retype New Password:</td>
     <td><input type=password name=new_pass2></td></tr>
   <tr>
     <td colspan=2 align=center>
     <input type=submit value="Change Password"></td></tr>
 </table>
 <input type="hidden" name="requested_id" value="<? echo $_SESSION['current_attendee_id'] ; ?>">
 </form>
<?php
}

function display_registration_form($values ="") {
?>
  Fields with <span class="redtext">*</span> are required<br>
 <form method=post action="<? echo $_SERVER['PHP_SELF'] ?>">
 <table>
   <tr>
     <td>Name<span class="redtext">*</span>: </td>
     <td><input type=text name=first_name size=25 maxlength=45 value="<? echo htmlspecialchars(stripslashes($values['first_name'])) ?>"><br><span class="smalltext">first</span></td>
     <td><input type=text name=last_name size=25 maxlength=45 value="<? echo htmlspecialchars(stripslashes($values['last_name'])) ?>"><br><span class="smalltext">last</span></td></tr>
   <tr>
     <td>Organization:</td>
     <td colspan="2"><input type=text name=organization size=30 maxlength=60 value="<? echo htmlspecialchars(stripslashes($values['organization'])) ?>"></td><td></td></tr>
   <tr>
     <td>Nickname:</td>
     <td colspan="3"><input type=text name=nickname size=15 maxlength=45 value="<? echo $values['nickname'] ?>"><span class="smalltext">Please note this is the name we will print on your convention badge.</span></td></tr>
   <tr>
     <td>Address<span class="redtext">*</span>:</td>
     <td colspan="2"><input type=text name=address1 size=25 maxlength=30 value="<? echo $values['address1'] ?>"></td><td></td></tr>
   <tr>
   <tr>
     <td></td>
     <td colspan="2"><input type=text name=address2 size=25 maxlength=30 value="<? echo $values['address2'] ?>"></td><td></td></tr>
    <tr>
      <td>City<span class="redtext">*</span>, State<span class="redtext">*</span>, Zip<span class="redtext">*</span>:</td>
      <td colspan="2">
        <input type="text" size="15" maxlength="25" name="city" value="<? echo $values['city'] ?>">
        <select name="state">
          <? include '/home/domains/uny-con.com/public_html/registration/includes/statelist.php' ; ?>
		</select> 
	    <input type="text" size="7" maxlength="6" name="zip" value="<? echo $values['zip'] ?>">
	  </td>
   </tr>
     <td>Country<span class="redtext">*</span>:</td>
     <td colspan="2"><select name="country">
		<? include '/home/domains/uny-con.com/public_html/registration/includes/countrylist.php' ; ?>
     </select>
     </td><td></td>
   </tr>
   <tr>
   <tr> 
      <td>Phone Number:</td>
      <td>(<input name="areacode" type="text" size="4" maxlength="3" value="<? echo $values['areacode'] ?>">)
        <input name="phone3" type="text" size="4" maxlength="3" value="<? echo $values['phone3'] ?>">
        - 
        <input name="phone4" type="text" size="5" maxlength="4" value="<? echo $values['phone4'] ?>"></td><td></td>
   </tr>
   <tr>
     <td>E-mail address<span class="redtext">*</span>:</td>
     <td colspan="2"><input type=text name=email_addr size=30 maxlength=60 value="<? echo $values['email_addr'] ?>"></td><td></td></tr>
   <tr>
     <td>RPGA Number:</td>
     <td colspan="2"><input type=text name=rpga_number size=12 maxlength=11 value="<? echo $values['rpga_number'] ?>"></td><td></td></tr>
<?
		echo "   <tr>
			<td>Username<span class=\"redtext\">*</span>:</td>
			<td valign=top><input type=\"";
		if ($values['update'] == 'Y') {
			echo 'hidden';
			} else {
			echo 'text';
			}
		echo "\" name=username size=16 maxlength=60 value=\"".$values['username']."\">";
		if ($values['update'] == 'Y') echo $values['username'];
		echo "</td><td></td></tr>";
		if ($values['update'] != 'Y') {
			echo "<tr>
			<td>Password<span class=\"redtext\">*</span> <span class=\"tiny\">(between 6 and 16 chars)</span>:</td>
			<td valign=top><input type=password name=password size=16 maxlength=16 value=\"".$values['password']."\"></td><td></td></tr>
			<tr>
			<td>Confirm password<span class=\"redtext\">*</span>:</td>
			<td><input type=password name=password2 size=16 maxlength=16 value=\"".$values['password']."\"></td><td></td></tr>";
			}
?>
   <tr>
     <td>Contact <span class="tiny">Allow us to contact you regarding other conventions and announcements about UNY-Con</span></td>
     <td valign=top><input type="checkbox" name="contact" value="t" <? if ($values['contact'] == "t" || !$values['contact']) {echo 'checked';}?>></td><td></td></tr>
   <tr>
     <td>Privacy: <span class="tiny">Allow us to share your contact info with other convention services</td>
     <td valign=top><input type=checkbox name="partner_contact" value="t" <? if ($values['partner_contact'] == "t" || !$values['partner_contact']) {echo 'checked';}?>></td><td></td></tr>
   <tr>
     <td>Share Schedule <span class="tiny">Allow others who know your email or username to view your schedule</span></td>
     <td valign=top><input type=checkbox name="others_viewing" value="t" <? if ($values['others_viewing'] == "t" || !$values['others_viewing']) {echo 'checked';}?>></td><td></td></tr>
<? if (isset($values['admin_add_user'])) { ?>
   <tr>
     <td>Registration Day:</td>
     <td colspan="2"><select name="event_day">
          <option value="all week-end" <? if ($values['event_day'] == 'all week-end' || $values['event_day'] == '') {echo 'Selected'; }?>>All week-end</option>
          <option value="friday" <? if ($values['event_day'] == 'friday') {echo 'Selected'; }?>>Friday</option>
          <option value="saturday" <? if ($values['event_day'] == 'saturday') {echo 'Selected'; }?>>Saturday</option>
          <option value="sunday" <? if ($values['event_day'] == 'sunday') {echo 'Selected'; }?>>Sunday</option>
        </select></td></tr>
   <tr>
     <td>Registration Type:</td>
     <td colspan="2"><select name="reg_type">
          <option value="" <? if ($values['reg_type'] == '') {echo 'selected'; }?>></option>
          <option value="general admit on-site" <? if ($values['reg_type'] == 'general admit on-site') {echo 'selected'; }?>>General Admittance On-Site</option>
          <option value="general admit coupon" <? if ($values['reg_type'] == 'general admit coupon') {echo 'selected'; }?>>General Admittance With Coupon</option>
          <option value="general admit pre-reg" <? if ($values['reg_type'] == 'general admit pre-reg') {echo 'selected'; }?>>General Admittance Pre-reg</option>
          <option value="gm" <? if ($values['reg_type'] == 'gm') {echo 'selected'; }?>>Game Master (4 events)</option>
          <option value="gm only" <? if ($values['reg_type'] == 'gm only') {echo 'selected'; }?>>Game Master Only</option>
          <option value="exhibitor" <? if ($values['reg_type'] == 'exhibitor') {echo 'selected'; }?>>Exhibitor</option>
         <option value="additional exhibitor" <? if ($values['reg_type'] == 'additional exhibitor') {echo 'selected'; }?>>Additional Exhibitor</option>
          <option value="LARP only" <? if ($values['reg_type'] == 'LARP only') {echo 'selected'; }?>>MET LARP Only</option>
          <option value="special guest" <? if ($values['reg_type'] == 'special guest') {echo 'selected'; }?>>Special Guest</option>
          <option value="staff" <? if ($values['reg_type'] == 'staff') {echo 'selected'; }?>>Staff</option>
          <option value="special" <? if ($values['reg_type'] == 'special') {echo 'selected'; }?>>Special</option>
          <option value="volunteer" <? if ($values['reg_type'] == 'volunteer') {echo 'selected'; }?>>Volunteer</option>
        </select></td></tr>
<?	} ?>
   <tr>
     <td colspan=3 align=center>
     <? if ($values['update'] == 'Y') echo '<input type=submit value="Update">';
	    else echo '<input type=submit value="Register">';
     ?>
     </td></tr>
 </table>
 <input type='hidden' name='timestamp' value='now()'>
 <input type='hidden' name='update' value='<? if ($values['update'] == 'Y') {echo 'Y';} else {echo 'N';} ?>'>
 <? if (isset($values['attendee_id']) && $_SESSION['admin'] == 't') echo "<input type='hidden' name='attendee_id' value='".$values['attendee_id']."'>\n"; ?>
 <? if (isset($values['admin_add_user']) && $_SESSION['admin'] == 't') echo "<input type='hidden' name='admin_add_user' value='".$values['admin_add_user']."'>\n"; ?>
 </form>
<?php 
}

function display_password_form()
{
  // display html change password form
?>
   <br />
   <form action="change_passwd.php" method=post>
   <table width=250 cellpadding=2 cellspacing=0 bgcolor=#cccccc>
   <tr><td>Old password:</td>
       <td><input type=password name=old_passwd size=16 maxlength=16></td>
   </tr>
   <tr><td>New password:</td>
       <td><input type=password name=new_passwd size=16 maxlength=16></td>
   </tr>
   <tr><td>Repeat new password:</td>
       <td><input type=password name=new_passwd2 size=16 maxlength=16></td>
   </tr>
   <tr><td colspan=2 align=center><input type=submit value="Change password">
   </td></tr>
   </table>
<?php
};

function display_forgot_form()
{
  // display HTML form to reset and email password
?>
   <br />
   <form action="forgot_passwd.php" method=post>
   <table>
   <tr><td colspan="2">Enter Username:</td></tr>
   <tr>
       <td><input type=text name=username size=16 maxlength=60></td>
   </tr>
   <tr><td colspan="2">Enter Email Address:</td></tr>
   <tr>
       <td><input type=text name=email_addr size=30 maxlength=60></td>
   </tr>
   <tr><td colspan=2><input type=submit value="Change password">
   </td>
   </table>
    <br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br><br><br><br>
<?php
};

function do_html_URL($url, $name)
{
  // output URL as link
?>
  <a href="<?php echo $url;?>"><?php echo $name;?></a>
<?php
}


function display_event_form($event_values ="")
{
?>
 <form method=post action="submit_event.php">
 <table>
     <td>Event Title<span class="redtext">*</span>: </td>
     <td colspan="2"><input type=text name=event_title size=50 maxlength=255 value="<? echo htmlspecialchars(stripslashes ($event_values['event_title'])) ?>"></td>
   <tr>
     <td class="grey_back">Game Type<span class="redtext">*</span>:</td>
     <td colspan="2"><select name="event_type">
          <option value="" <? if ($event_values['event_type'] == "") {echo "Selected"; }?>></option>
          <option value="Board Game" <? if ($event_values['event_type'] == "Board Game") {echo "Selected"; }?>>Board Game</option>
          <option value="Collectible Card" <? if ($event_values['event_type'] == "Collectible Card") {echo "Selected"; }?>>Collectible Card</option>
          <option value="Computer Game" <? if ($event_values['event_type'] == "Computer Game") {echo "Selected"; }?>>Computer Game</option>
          <option value="LARP" <? if ($event_values['event_type'] == "LARP") {echo "Selected"; }?>>LARP</option>
          <option value="Role-playing" <? if ($event_values['event_type'] == "Role-playing") {echo "Selected"; }?>>Role-playing</option>
          <option value="Miniature Game" <? if ($event_values['event_type'] == "Miniature Game") {echo "Selected"; }?>>Miniature</option>
          <option value="Seminar" <? if ($event_values['event_type'] == "Seminar") {echo "Selected"; }?>>Seminar</option>
          <option value="RPGA" <? if ($event_values['event_type'] == "RPGA") {echo "Selected"; }?>>RPGA</option>
        </select></td></tr>
   <tr>
     <td>Game System<span class="redtext">*</span>:</td>
     <td colspan="2"><input type=text name=game_system size=30 maxlength=50 value="<? echo htmlspecialchars(stripslashes ($event_values['game_system'])) ?>"></td></tr>
   <tr>
<td class="grey_back">Minimum # players<span class="redtext">*</span>:</td>
<td><input name="min_players" type="text" size="3" maxlength="2" value="<? echo stripslashes ($event_values['min_players']) ?>"><span class="smalltext">(numbers only)</span></td></tr>
      <tr>
      <td>Maximum # players<span class="redtext">*</span>:</td>
      <td colspan="2"><input name="max_players" type="text" size="4" maxlength="3" value="<? echo stripslashes ($event_values['max_players']) ?>"><span class="smalltext">(numbers only)</span></td>
    <tr>
      <td class="grey_back">Difficulty Level<span class="redtext">*</span>:</td>
      <td colspan="2"><select name="difficulty">
          <option value="" <? if ($event_values['difficulty'] == "") {echo "Selected"; }?>></option>
          <option value="1" <? if ($event_values['difficulty'] == "1") {echo "Selected"; }?>>1 Easy</option>
          <option value="2" <? if ($event_values['difficulty'] == "2") {echo "Selected"; }?>>2 Almost easy</option>
          <option value="3" <? if ($event_values['difficulty'] == "3") {echo "Selected"; }?>>3 Moderate</option>
          <option value="4" <? if ($event_values['difficulty'] == "4") {echo "Selected"; }?>>4 Difficult</option>
          <option value="5" <? if ($event_values['difficulty'] == "5") {echo "Selected"; }?>>5 Impossible</option>
        </select></td>
      <tr>
      <td>Knowledge Level<span class="redtext">*</span>:</td>
      <td colspan="2"> 
          <label> 
          <input type="radio" name="familiarity" value="1" <? if ($event_values['familiarity'] == "1") {echo 'checked'; }?>>
          </label>
          1. NONE <span class="smalltext">Will teach the system before or during the session</span><br>
          <label> 
          <input type="radio" name="familiarity" value="2" <? if ($event_values['familiarity'] == "2") {echo 'checked'; }?>>
          </label>
          2. BASIC <span class="smalltext">Some knowledge would be beneficial</span><br>
          <label> 
          <input type="radio" name="familiarity" value="3" <? if ($event_values['familiarity'] == "3") {echo 'checked'; }?>>
          </label>
          3. AVERAGE <span class="smalltext">Players should know how the rules and world</span><br>
          <label>
          <input type="radio" name="familiarity" value="4" <? if ($event_values['familiarity'] == "4") {echo 'checked'; }?>>
          </label>
          4. EXPERT <span class="smalltext">We won't have time to waste looking up rules in the book</span>
        </td>
    </tr>
    <tr> 
      <td class="grey_back">Will your event contain Mature themes?<span class="redtext">*</span></td>
      <td colspan="2"> <select name="maturity" size="1">
          <option value="" <? if ($event_values['maturity'] == "") {echo "Selected"; }?>></option>
          <option value="N" <? if ($event_values['maturity'] == "N") {echo "Selected"; }?>>No</option>
          <option value="M" <? if ($event_values['maturity'] == "M") {echo "Selected"; }?>>Maybe</option>
          <option value="Y" <? if ($event_values['maturity'] == "Y") {echo "Selected"; }?>>Yes</option>
        </select></td>
    </tr>
    <tr> 
      <td>Starting Time<span class="redtext">*</span><span class="smalltext"> Recommended starting times are listed in <span class="bold">bold.</span></span></td>
      <td>
      	<select name="multi_start_time[]">
      	<option></option>
      	<? $start = $event_values['multi_start_time'];
      	print_starting_time_list($start['0']) ?>
      	</select>
      </td>
    </tr>
    <tr>
    	<td class="grey_back"><span>How many times will you run this event?</span><span class="tiny">You will be prompted for additional starting times once you click submit if you run more than one session</span>
    	</td>
    	<td>
    	<select name="multi_session">
	  		<option value="1" <? if ($event_values['multi_session'] != 't') {echo "Selected"; }?>>1</option>
	  		<option value="2" <? if ($event_values['multi_session'] == 't') {echo "Selected"; }?>>2</option>
	  		<option value="3" <? if ($event_values['multi_session'] == 't') {echo "Selected"; }?>>3</option>
	  		<option value="4" <? if ($event_values['multi_session'] == 't') {echo "Selected"; }?>>4</option>
	  		<option value="5" <? if ($event_values['multi_session'] == 't') {echo "Selected"; }?>>5</option>
	  		<option value="6" <? if ($event_values['multi_session'] == 't') {echo "Selected"; }?>>6</option>
      	</select>
    	</td>
    </tr>
    <tr> 
      <td>How long will this event last?</td>
      <td colspan="2"> <select name="duration">
      					<option></option>
      <? for($i=1;$i<=24;$i++)
      		{
          		echo "<option value=\"$i\"";
          		if ($event_values['duration'] == "$i") { echo "selected=\"selected\""; }
          		echo ">$i";
          		if($i=="1") { echo " hour"; }
          		else { echo " hours"; }
          		echo "</option>";
         	}
       ?>
        </select></td>
    </tr>
<!--    <tr> 
      <td>How many Instances of this event will be run in the above timeslot<span class="redtext">*</span>:</td>
      <td colspan="2"> <input name="num_of_tables" type="text" size="6" maxlength="2" value="<? echo stripslashes ($event_values['num_of_tables']) ?>"><span class="smalltext">use numbers only please</span>
       </td>
    </tr>
 -->
    <tr> 
      <td class="grey_back">If the event has an additional cost how much is it?</td>
      <td colspan="2">$ <input name="cost" type="text" size="8" maxlength="8" value="<? echo stripslashes ($event_values['cost']) ?>"><span class="smalltext">this is an event cost in addition to convention registration fees, this usually only applies to tournaments, use numbers only please</span>
      </td>
    </tr>
    <tr> 
      <td>Anything Players need to bring</td>
    	<td colspan="2">
        <input type="text" maxlength="100" name="equipment" value="<? echo htmlspecialchars(stripslashes ($event_values['equipment'])) ?>" size="50"></td>
	</tr>
    <tr> 
      <td>Event Description<span class="redtext">*</span>:</td>
      <td colspan="2"> 
        <textarea name="description" cols="50" rows="16"><? echo stripslashes ($event_values['description']) ?></textarea>
      </td>
    </tr>
	<tr>
	  <td class="grey_back">Notes/Special Needs:<span class="smalltext">this information is not displayed on event pages</span></td>
      <td colspan="2">
       <textarea name="notes" cols="50" rows="3"><? echo stripslashes ($event_values['notes']) ?></textarea></td>
	</tr>
<? if(isset($organization)) { ?>
	<tr> 
	  <td>Display Organization?</td>
	  <td colspan="2">
	  	<select name="display_org">
	  		<option value="f" <? if ($event_values['display_org'] != 't') {echo "Selected"; }?>>No</option>
	  		<option value="t" <? if ($event_values['display_org'] == 't') {echo "Selected"; }?>>Yes</option>
      	</select>
      	<span class="smalltext"> display your organization (if you have one entered) as the GM for this event.</span></td>
	</tr>
<?	} if(isset($organizer)) { ?>
	<tr> 
	  <td class="grey_back">Are you GMing this event?</td>
	  <td colspan="2">
  	  	<select name="GM">
	  		<option value="f">No</option>
	  		<option value="t" Selected>Yes</option>
      	</select>
		<span class="smalltext"> in all of its time slots, if you are gming the event in only some if its timeslots then you need to submit it and sign upto run it in the individual time slots.</span></td>
	</tr>
  <? } ?>
  <?  if ($_SESSION['admin'] == 't') { ?>
	<tr>
	<td colspan="3" class="grey_back">You are seeing this section of the form because you are an administrator</td>
	</tr>
	<tr>
	  <td>Approved:</td>
	  <td colspan="2">
	    <select name="approved">
	      <option value="f" <? if ($event_values['approved'] != 't') {echo "Selected"; }?>>No</option>
	      <option value="t" <? if ($event_values['approved'] == 't') {echo "Selected"; }?>>Yes</option>
      </select></td>
    </tr>
	<tr>
	  <td class="grey_back">Is this a featured event:</td>
	  <td colspan="2">
	    <select name="featured">
	      <option value="f" <? if ($event_values['featured'] != 't') {echo "Selected"; }?>>No</option>
	      <option value="t" <? if ($event_values['featured'] == 't') {echo "Selected"; }?>>Yes</option>
      </select></td>
   </tr>
	<tr>
	  <td>Cancelled:</td>
	  <td colspan="2">
	    <select name="cancelled">
	      <option value="f" <? if ($event_values['cancelled'] != 't') {echo "Selected"; }?>>No</option>
	      <option value="t" <? if ($event_values['cancelled'] == 't') {echo "Selected"; }?>>Yes</option>
      </select></td>
   </tr>
	<tr>
	  <td class="grey_back">Show this event as changed:</td>
	  <td colspan="2">
	    <select name="show_change">
	      <option value="f" <? if ($event_values['show_change'] != 't') {echo "Selected"; }?>>No</option>
	      <option value="t" <? if ($event_values['show_change'] == 't') {echo "Selected"; }?>>Yes</option>
      </select></td>
   </tr>
	<tr>
	  <td class="grey_back">Change Description:</td>
      <td colspan="2">
       <textarea name="change_description" cols="50" rows="3"><? echo stripslashes ($event_values['change_description']) ?></textarea></td>
	</tr>
  <? } ?>
   <tr>
     <td colspan=3 align=center>
     <input type=submit value="Submit Event"></td></tr>
 </table>
  <?  if ($_SESSION['admin'] != 't') { ?>
 <input type='hidden' name='approved' value="<? if ($event_values['approved'] == 't') {echo 't';} else {echo 'f';} ?>">
 <input type='hidden' name='featured' value="<? if ($event_values['featured'] == 't') {echo 't';} else {echo 'f';} ?>">
 <input type='hidden' name='cancelled' value="<? if ($event_values['cancelled'] == 't') {echo 't';} else {echo 'f';} ?>">
 <input type='hidden' name='show_change' value="<? if ($event_values['cshow_change'] == 't') {echo 't';} else {echo 'f';} ?>">
 <input type='hidden' name='change_description' value="<? echo htmlspecialchars(stripslashes($event_values['change_description'])) ?>">
  <? } ?>
 <input type='hidden' name='timestamp' value='now()'>
 <input type='hidden' name='update' value="<? if ($event_values['update'] == 'Y') {echo 'Y';} else {echo 'N';} ?>">
 </form>
<?php 

}

function print_event_table($result, $display_type = 'normal', $user_attendee_id = '')
{
	//This function takes as input a postgres array and formats the output as a table.

	//we will get some variables to be used later on
	if (empty($user_attendee_id)) {
		$user_attendee_id = $_SESSION['current_attendee_id'];
		}
		
	$admin = $_SESSION['admin'];
	$page = $_SERVER['PHP_SELF'];
	if ($_GET['sortdir'] == ASC) $sortdir = DESC;
		else $sortdir = ASC;
	if (isset($_GET['searchtype'])) $searchstring = 'searchtype='.$_GET['searchtype'].'&searchterm='.$_GET['searchterm'].'&';
	if (pg_numrows($result) == 0) return false ;
	$num = pg_numrows($result);
	$i=0;
	while ($i < $num) {
		$values = recordproc($result, $i);
		extract($values);
		$current_st = $start_time;
		//get the current number registered for the event
		if (check_valid_user()) {
			$currplayers = get_current_num_players($event_id, $start_time);
			$gming_playing = check_attendee_event($user_attendee_id, $event_id, $start_time);
			if ($currplayers >= $max_players) {
				$playgmlink = "Full/<a href=\"gm_signup.php?action=add&amp;event_id=$event_id&amp;start_time=".$current_st."\">GM</a>";
				} elseif ($currplayers < $max_players) {
				$playgmlink = "<a href=\"event_signup.php?action=add&amp;event_id=$event_id&amp;start_time=".$current_st."\">Play</a>/<a href=\"gm_signup.php?action=add&amp;event_id=$event_id&amp;start_time=".$current_st."\">GM</a>";
				}
			}
/*		if ($num_of_timeslots == '1') $num_of_timeslots = '';
		if ($num_of_timeslots > '1') {
			$num_of_timeslots = "<span class=\"redtext\">*</span>";
			$multi_ts_warning = "<span class=\"redtext\">*</span> Event lasts multiple timeslots, please be careful not to overbook yourself!";
			} */
		//This checks to see what timeslot the current record is in. If we have moved to a new timeslot from the previous record we close the previous table and start a new one.
		if ($working_st != $current_st) {
			$working_st = $current_st;
			if ($i != 0) echo "</table>\n";
			?>
			<h2><? echo print_time_start($current_st)."<a href=\"http://loki.local/~plummer/uny-con/registration/eventdetails.php?searchtype=start_time&amp;searchterm=$current_st\">$eventtype " ?> Details</a></h2>
			<table>
				<tr class="grey_back">
					<?php 
					if (check_valid_user()) echo "<th class=\"eventlistleft\">Action</th>\n";
					echo "<th class=\"eventlist\">Start Time</th>\n";
					//if ($display_type == 'attend') echo "<th class=\"eventlist\">status</th>\n";
					//if ($display_type == 'signup') echo "<th class=\"eventlistleft\">Signup</th>\n";
					//if ($admin == 't' && $display_type == 'approval') echo "<th class=\"eventlistleft\"><a href=\"$page?TS=$start_time&"."$searchstring"."sortkey=approved&sortdir=$sortdir\">Approved</a></th>\n";
					//echo "<th class=\"eventlistleft\"><a href=\"$page?TS=$start_time&"."$searchstring"."sortkey=event_id&sortdir=$sortdir\">Event ID</a></th>";
					if ($display_type == 'GM' || $admin == 't') { echo "<th class=\"eventlist\">Players</th>\n"; }
					echo "<th class=\"eventlist\"><a href=\"$page?TS=$start_time&amp;"."$searchstring"."sortkey=event_type&sortdir=$sortdir\">Event Type</a></th>";
					echo "<th class=\"eventlist\">Cost</th>";
					echo "<th class=\"eventlist\"><a href=\"$page?TS=$start_time&amp;"."$searchstring"."sortkey=game_system&sortdir=$sortdir\">Location</a></th>";
					echo "<th class=\"eventlist\"><a href=\"$page?TS=$start_time&amp;"."$searchstring"."sortkey=game_system&sortdir=$sortdir\">Game System</a></th>";
					echo "<th class=\"eventlist\"><a href=\"$page?TS=$start_time&amp;"."$searchstring"."sortkey=event_title&sortdir=$sortdir\">Event Title</a></th>";
					echo "<th class=\"eventlist\"><a href=\"$page?TS=$start_time&amp;"."$searchstring"."sortkey=attendee.last_name&sortdir=$sortdir\">GM<a/></th>";
				echo "</tr>";
			}
?><?
    echo "<tr$silverback>";
		if (check_valid_user() && ($_SESSION['admin'] == 't' || (!check_attendee_timeslot_reg($user_attendee_id, $start_time, $duration) || $gming_playing == 'gm' || $gming_playing == 'player'))) { 
			echo "<td class=\"eventlist\">";
			if (!$gming_playing && $cancelled != 't') {
				echo "$playgmlink";
				}
			elseif ($gming_playing == 'gm') {
				echo "<a href=\"gm_signup.php?action=delete&amp;event_id=$event_id&amp;start_time=".$current_st."\">Drop GMing</a>";
				}
			elseif ($gming_playing == 'player') {
				echo "<a href=\"event_signup.php?action=delete&amp;event_id=$event_id&amp;start_time=".$current_st."\">Drop</a>";
				}
			echo "</td>";
			} elseif (check_valid_user()) {
			echo "<td class=\"eventlist\">&nbsp;</td>";
			}
		$start = date('ga', (strtotime($start_time)));
		echo "<td class=\"eventlist\">".$start." </a></td>"; 
		if ($display_type == 'GM' || $admin == 't') { 
				 echo "<td class=\"eventlist\"><a href=\"event_attendees.php?event_id=$event_id&time_start=$current_ts\">$currplayers".'/'."$max_players</a></td>";
			}
	  ?>
      <td class="eventlist"><? echo "<a href=\"$page?searchtype=event_type&searchterm=$event_type\" title=\"View all events of this type.\">$event_type"; ?></a></td>
	  <td class="eventlist">$<? echo "$cost"; ?></td>
	  <td class="eventlist"><? echo "$assigned_room &nbsp;"; ?></td>
      <td class="eventlist"><? echo "$game_system"; ?></td>
      <td class="eventlist"><? echo "<a href=\"http://loki.local/~plummer/uny-con/registration/eventdetails.php?searchtype=eventid&searchterm=$event_id\">$event_title</a>"; if (($admin == 't' || $user_attendee_id == $attendee_id) && ($display_type == 'GM' || ($admin == 't' && $display_type != 'attend' && $display_type != 'signup'))) echo " <a href=\"submit_event.php?event_id=$event_id\" title=\"Edit all characteristics of this event.\">[Edit]</a>"; if ($cancelled == 't') {echo "<span class=\"redtext\"><strong> Cancelled!</strong></span>";} else {if ($approved == 'f') echo "<span class=\"red\"><strong> Pending Approval</strong></span>";}?></td>
      <td class="eventlist"><? echo "<a href=\"$page?searchtype=gm&searchterm=$attendee_id\" title=\"View all events run by this GM.\">$name"; ?></a></td>
    </tr>
<?
	if (oddeven($i) == 'even') $silverback = " class=\"silver_back\"";
	if (oddeven($i) == 'odd') $silverback = "";
	unset($gming_playing, $playgmlink, $currplayers, $max_players);
    ++$i;
    }
  echo '</table>';
}

function print_event_details($result, $num = 0)
{
  //This function prints a detailed listing of a given postgres formatted event
    //we will get some variables to be used later on
  $user_attendee_id = $_SESSION['current_attendee_id'];
  if (isset($_SESSION['current_attendee_id'])) $user_attendee_id = $_SESSION['current_attendee_id'];
  $admin = $_SESSION['admin'];

  $values=recordproc($result, $num);
  extract($values);
  $event_time = str_replace("\n",", ",rtrim(print_event_time_start($event_id)));
  $eventcodes = str_replace("\n",", ",rtrim(print_event_codes($event_id)));
?>
	  <h1><? echo "$event_title"; ?></h1>
	<? if ($cancelled == 'Y') {echo "<span class=\"redtext\"><strong> Cancelled!</strong></span><br>";}?>
	<strong>Event Duration:</strong> <? if($duration == "1") { echo "$duration hour"; } else { echo "$duration hours"; } ?><br>
	<strong>Event IDs:</strong> <? echo "$eventcodes"; ?><br>
	<strong>Event Type:</strong> <? echo "<a href=\"event_list.php?searchtype=event_type&searchterm=$event_type\">$event_type"; ?></a><br>
	<strong>Game System:</strong> <? echo "$game_system"; ?><br>
	<strong>Location:</strong> <? echo "$assigned_room"; ?><br>
	<table>
	<tr>
	<td align="left"><strong>Minimum Players:</strong> <? echo "$min_players"; ?></td>
	<td align="right"><strong>Maximum Players:</strong> <? echo  "$max_players"; ?></td>
	</tr><tr>
	<td align="left"><strong>Familiarity:</strong> <? echo "$processed_familiarity"; ?></td>
	<td align="right"><strong>Difficulty:</strong> <? echo  "$processed_difficulty"; ?></td>
	</tr><tr>
	<td align="left"><strong>Mature Themes:</strong> <? echo  "$processed_maturity"; ?></td>
	<td align="right"></td>
	</tr>
	</table>
	
	<? if ($cost != "0") {
	echo '<strong>Additional Cost:</strong> $'."$cost<br>\n"; } ?>
	<p><strong>Description:</strong> <? echo str_replace( "\n", "</p><p>", $description); ?></p>
	<? if ($equipment != "") {
	echo "<i>Attendees should bring $equipment</i><br>\n"; }
				else {
				$equipment = "1";
				} ?>
	
	<strong>GM:</strong> <? echo "<a href=\"event_list.php?searchtype=gm&searchterm=$attendee_id\">$name"; ?></a><br>
	<? if ($showchange == 'Y') {echo "<span class=\"greentext\">This event was modified on $modified</span><br>
	<strong>Description of change:</strong> $processed_change_description<br>";} 
	if (check_valid_user()) {
		$reg_status = get_con_attendance_status($user_attendee_id);
		$max_players = get_max_players_for_event($event_id);
		  if ( ($reg_status == "approved") || ($reg_status == "pending") ) {
			echo "Click on the appropriate link to signup for the event<br>";
			$timestarts = get_event_start_times($event_id);
			foreach ($timestarts as $ts) {
				$currplayers = get_current_num_players($event_id, $ts);
				if (!check_attendee_timeslot_reg($user_attendee_id, $ts, $duration) && $max_players > $currentplayers)
					echo "<a href=\"event_signup.php?action=add&amp;event_id=$event_id&amp;start_time=$ts\">";
				$tstime = print_time_start($ts);
				echo $tstime;
				if (!check_attendee_timeslot_reg($user_attendee_id, $ts, $duration))
					echo "</a>";
				echo "<br />";
				}
			}
		}
}

function display_event_cogm($result)
{
	$page = $_SERVER['PHP_SELF'];
	//this function takes a postgres return resource and creates a table with approval for cogms of events.
	echo "\n<form name=co_gm_approval_table action=\"$page\" method=post>\n";
	$num = pg_numrows($result);
	$i=0;
	while ($i < $num) {
		$values = recordproc($result, $i);
		extract($values);
		unset($cogmapproved, $cogmdenied);
		if ($approved == 't') $cogmapproved = 'checked' ;
		if ($denied == 't') $cogmdenied = 'checked' ;
		//This checks to see what timeslot the current record is in. If we have moved to a new timeslot fromt he previous record we clos the previous table and start a new one, otherwise we skip it.
		$current_ts = $start_time;
		if ($working_ts != $current_ts) {
			$working_ts = $current_ts;
			if ($i != 0) echo "</table>\n";
			?>
			<h2 class="mediumtext"><? echo print_timeslot($current_ts) ?></h2>
			<table>
				<tr class="grey_back">
					<th class="eventlist"><strong>Event ID</strong></th>
					<th class="eventlist"><strong>Co-GM Name</strong></th>
					<th class="eventlist"><strong>Event Title</strong></th>
					<th class="eventlist"><strong>Approve</strong></th>
					<th class="eventlist"><strong>Deny</strong></th>
				</tr>
			<?php
			}
?>
    <tr>
      <td class="eventlist"><? echo 'TS' . $start_time . $event_id; ?></td>
      <td class="eventlist"><? echo "$name"; ?></td>
      <td class="eventlist"><? echo "$event_title"; ?></td>
      <td class="eventlist"><? echo "<input type=checkbox name=\"approve_co_gm[]\" value=\"$gm_id.$start_time.$event_id\" $cogmapproved>"; ?></td>
      <td class="eventlist"><? echo "<input type=checkbox name=\"remove_co_gm[]\" value=\"$gm_id.$start_time.$event_id\" $cogmdenied>"; ?></td>
    </tr>
<?
    ++$i;
    }
?>
	</table>
	<input type="submit" value="Update Co-GMs">
	</form>
<?php
}

function print_event_gm_manage_table($result) {
	// This function takes a pg result resource and prints out a table with the event title, Event ID, Max numbers of players, Current number of players, Number of judges needed, Current number of judges, Number of extra judges.
	
	echo "<table>\n";
	$tablehead =  "	<tr class=\"grey_back\">\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Event Title</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Max<br />Players</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Max GMs<br />needed</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Curr<br />Players</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Curr<br />GMs</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>GMs Curr<br />Needed</strong></th>\n";
	$tablehead .= "		<td class=\"eventlist\"><strong>Curr<br />Extra GMs</strong></th>\n";
	$tablehead .= "	</tr>\n";
	$num = pg_numrows($result);
	$i=0;
	while ($i < $num) {
		$values = recordproc($result, $i);
		extract($values);
		//This checks to see what timeslot the current record is in. If we have moved to a new timeslot fromt he previous record we clos the previous table and start a new one, otherwise we skip it.
		if ($event_type = 'RPGA') {
		$current_ts = $start_time;
		if ($working_ts != $current_ts) {
			$working_ts = $current_ts;
			echo "	<tr class=\"eventlist_ts\">\n";
			echo "\t\t<td colspan=\"8\" class=\"eventlist_ts\">".print_time_start($current_ts)."</td>\n";
			echo "	</tr>\n";
			echo "$tablehead";
			}
		 if ($_SESSION['admin'] == 't' || $attendee_id == $_SESSION['attendee_id']) {
		 	$edit = " <a href=\"submit_event.php?event_id=$event_id\" title=\"Edit all characteristics of this event.\">[Edit]</a>";
		 	}
		 if ($cancelled == 't') {
		 	$cancelledtext = " <span class=\"redtext\"><strong>Cancelled!</strong></span>";
		 	} 
		 if ($approved == 'f') {
		 	$approvedtext = "<strong> Pending Approval</strong></span>";
		 	}
		$current_num_players = get_current_num_players($event_id, $current_ts);
		$current_num_gms = get_num_of_gms($event_id, $current_ts, approved);
		$max_num_gms_needed = $max_players/6;
		$num_gms_curr_needed = ceil($current_num_players/6);
		$extra_gms = $current_num_gms - $num_gms_curr_needed;
		if ($extra_gms >= 0) {
			$need_gms = "<span class=\"greentext\">0</span>";
			}
		if ($extra_gms < 0) {
			$need_gms = abs($extra_gms);
			$need_gms = "<span class=\"redtext\">$need_gms</span>";
			$extra_gms = 0;
			}
		if (get_num_of_gms($event_id, $current_ts, unapproved) > 0) {
			$current_num_gms = "<a href=\"manage_gms.php?status=unapproved\" title=\"Go to approve the GMs.\">$current_num_gms</a><span class=\"redtext\">*</span>";
			}
		echo "\t<tr>\n";
		?>
		<td class="eventlist"><? echo $event_title . $edit . $cancelledtext . $approvedtext ; ?></td>
		<td class="eventlist_silver"><? echo "$max_players" ; ?></td>
		<td class="eventlist"><? echo "$max_num_gms_needed" ; ?></td>
		<td class="eventlist_silver"><? echo "$current_num_players" ; ?></td>
		<td class="eventlist"><? echo "$current_num_gms" ; ?></td>
		<td class="eventlist_silver"><? echo "$need_gms" ; ?></td>
		<td class="eventlist"><? echo "$extra_gms" ; ?></td>
		</tr>
		<?
		unset($edit, $cancelled, $approved, $need_gms, $extra_gms);
		$i++;
		}
	}
}

function print_signup_event_table($result, $user_attendee_id = '') {
  //This function takes as input a postgres array and formats the output as a table.
  //we will get some variables to be used later on
  if (empty($user_attendee_id))
  	$user_attendee_id = $_SESSION['current_attendee_id'];
  $page = $_SERVER['PHP_SELF'];
  if (pg_numrows($result) == 0) return false ;

  echo "<table>";
    echo "<tr class=\"grey_back\">";
      echo "<th class=\"eventlist\"><strong>Signup</strong></th>";
      echo "<th class=\"eventlist\"><strong>Players</strong></th>";
      echo "<th class=\"eventlist\"><strong>Event ID</strong></th>";
      echo "<th class=\"eventlist\"><strong>Event Type</strong></th>";
      echo "<th class=\"eventlist\"><strong>Event Cost</strong></th>";
      echo "<th class=\"eventlist\"><strong>Game System</strong></th>";
      echo "<th class=\"eventlist\"><strong>Event Title</strong></th>";
      echo "<th class=\"eventlist\"><strong>GM</strong></th>";
    echo "</tr>";

  $num = pg_numrows($result);
  $i=0;

  while ($i < $num) {
   $values = recordproc($result, $i);
   extract($values);

   if ($cost == 0.00) $cost = "&nbsp;";
   
   $max_players = get_max_players_for_event($event_id);
   $currplayers = get_current_num_players($event_id, $start_time);
  
   echo "<tr>";
      if ($max_players > $currplayers) {
      	echo "<td class=\"eventlist\">";
      	if (!check_attendee_timeslot_reg ($user_attendee_id, $start_time, $duration) || $_SESSION['admin'] == 't') echo "<a href=\"".$_SERVER['PHP_SELF']."?action=add&amp;eventid=$event_id&amp;start_time=".$start_time."\">Play</a>/<a href=\"gm_signup.php?action=add&amp;eventid=$event_id&amp;start_time=".$start_time."\">GM</a>"; 
		echo "</td>";
      } else {
      	echo "<td class=\"eventlist\">&nbsp;</td>";
      }

      echo "<td class=\"eventlist\">$currplayers".'/'."$max_players</td>";
      echo "<td class=\"eventlist\">TS". $start_time . $event_id."</a></td>";
      echo "<td class=\"eventlist\">$event_type</td>";
      echo "<td class=\"eventlist\">$cost</td>";
      echo "<td class=\"eventlist\">$game_system</td>";
      echo "<td class=\"eventlist\"><a href=\"eventdetails.php?searchtype=eventid&searchterm=$event_id\">$event_title</td>";
      echo "<td class=\"eventlist\">$name</td>";
    echo "</tr>";

    ++$i;
    }
  echo "</table>";
}

function print_room_assignment_table($result, $room_menu) {
  //This function takes as input a postgres array and formats the output as a table.
	if (pg_numrows($result) == 0) return false ;
	//This checks to see what timeslot the current record is in. If we have moved to a new timeslot fromt he previous record we clos the previous table and start a new one, otherwise we skip it.
	echo "<form method=post action=\"assign_rooms.php\">";
	$num = pg_numrows($result);
	$i=0;
	while ($i < $num) {
		$values = recordproc($result, $i);
		extract($values);
		$current_ts = $start_time;
		if ($working_ts != $current_ts) {
			$working_ts = $current_ts;
			if ($i != 0) echo "</table>\n";
			echo "<h2 class=\"mediumtext\">".print_timeslot($current_ts)."</h2>";
			echo "<table>\n";
			echo "<tr class=\"grey_back\">\n";
				echo "<th class=\"eventlist\"><strong>Players</strong></th>\n";
				echo "<th class=\"eventlist\"><strong>Event Type</strong></th>\n";
				echo "<th class=\"eventlist\"><strong>Game System</strong></th>\n";
				echo "<th class=\"eventlist\"><strong>Event Title</strong></th>\n";
				echo "<th class=\"eventlist\"><strong>GM</strong></th>\n";
				echo "<th class=\"eventlist\"><strong>Room</strong></th>\n";
			echo "</tr>\n";
			}
		echo "<tr>\n";
		$currplayers = get_current_num_players($event_id, $start_time);
		  echo "<td class=\"eventlist\">$currplayers".'/'."$max_players</td>\n";
		  echo "<td class=\"eventlist\">$event_type</td>\n";
		  echo "<td class=\"eventlist\">$game_system</td>\n";
		  echo "<td class=\"eventlist\"><a href=\"eventdetails.php?searchtype=eventid&searchterm=$event_id\">$event_title</td>\n";
		  echo "<td class=\"eventlist\">$name</td>\n";
		  $room_menu2 = create_room_menu($assigned_room);
		  echo "<td class=\"eventlist\"><select name=\"room_assignments[$start_time.$event_id]\">$room_menu2</select></td>\n";
		echo "</tr>\n";
		$i++;
		}
	echo "</table>";
	echo "<input type=\"submit\" value=\"Assign Rooms\">";
	echo "</form>";

}

function display_con_registration_form() {
  //This function takes no input
  //but outputs a table to signup for a given day
  echo "<form method=post action=\"register_for_con.php\">";
  echo "<select name=\"date_select\">";
  echo "<option value=\"all week-end\" selected>All Week-end - $25.00 Pre-Reg</option>";
  echo "<option value=\"friday\">Friday - $15.00</option>";
  echo "<option value=\"saturday\">Saturday - $20.00</option>";
  echo "<option value=\"sunday\">Sunday - $20.00</option>";
  echo "<option value=\"LARP only\">MET LARP only - $7.00</option>";
  echo "</select>";
  echo "<input type=\"submit\" value=\"Submit Your Registration\">";
  echo "</form>";
}

function print_paypal_links($pendingevents, $user_attendee_id) {
	//This function will print the paypal links to pay for a particular event. It expects $pendingevents to be a postgres return resopurce of all the events you want to print links for.
	$LARPevent_id = "9153";
	$number_of_LARPS = 0;
	$num = pg_num_rows($pendingevents);
	$i = 0;
	while ($i < $num) {
		$values = recordproc($pendingevents, $i);
		extract($values);
		//Ugly hack to prevent multiple charges for LARP
		if ($number_of_LARPS == '0' || $event_id != '9153') {
		$itemnumber = "TS"."$start_time"."$event_id";
			echo "Registration for $itemnumber<br/>\n";
			echo "$event_title<br />\n";
	    echo "<strong>$cost Event (USD)</strong><br />\n";
		    echo "<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">\n";
		    echo "<input type=\"hidden\" name=\"cmd\" value=\"_cart\">\n";
		    echo "<input type=\"hidden\" name=\"business\" value=\"registration@uny-con.com\">\n";
			echo "<input type=\"hidden\" name=\"item_name\" value=\"$event_title\">\n";
			echo "<input type=\"hidden\" name=\"item_number\" value=\"$itemnumber\">\n";
			echo "<input type=\"hidden\" name=\"amount\" value=\"$cost\">\n";
		    echo "<input type=\"hidden\" name=\"no_note\" value=\"1\">\n";
		    echo "<input type=\"hidden\" name=\"currency_code\" value=\"USD\">\n";
			echo "<input type=\"hidden\" name=\"custom\" value=\"$user_attendee_id\">\n";
		    echo "<input type=\"hidden\" name=\"image_url\" value=\"http://loki.local/~plummer/uny-con/registration/images/PayPal-UNY-head-with-text-C.gif\">\n";
		    echo "<input type=\"hidden\" name=\"lc\" value=\"US\">\n";
		    echo "<input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/sc-but-01.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\">\n";
		    echo "<input type=\"hidden\" name=\"add\" value=\"1\">\n";
		    echo "</form>\n";
		}
		
		if ($event_id == $LARPevent_id) $number_of_LARPS = $number_of_LARPS + 1;
	    ++$i;
	    }
}

function create_room_menu($assigned_room) {
	$room_array=get_rooms();
	$select_option = "\n<option></option>\n";
	foreach ($room_array as $thisroom) {
		$select_option .= "<option value=\"".$thisroom['room_name']."\"";
		//if existing room put the menu selected to that
		if ($thisroom['room_name'] == $assigned_room)
			$select_option .= ' selected';
		$select_option .= ">";
		$select_option .= $thisroom['room_name']."</option>\n";
		}
	return $select_option;
}

function display_user_info($userinfo) {
	//this function takes an array of user info as input and outputs it
	extract($userinfo);
	if (empty($checked_inepoch) && $_SESSION['admin'] == 't') {
		$checked_in = "<a href=\"".$_SERVER['PHP_SELF']."?check_in=Y\">[Check-in]</a>";
		} elseif (!empty($checked_inepoch)) {
		$checked_in = "Checked in ".date('m-d-Y g:ia',$checked_inepoch)." ";
		}
	$amount_owed = get_attendee_amount_owed($attendee_id);
	$amount_paid = get_attendee_amount_paid($attendee_id);
	$balance = $amount_owed - $amount_paid;
	if ($balance > '0') { $balance = "<span class=\"redtext\"><strong>$balance</strong></span>" ; }
	if (!empty($address2)) $street_address = "$address1<br />$address2";
	if (empty($address2)) $street_address = "$address1";
	echo "<h1>Info for $first_name $last_name <span class=\"smalltext\"><a href=\"register_form.php?requested_id=$attendee_id&update=Y\">[edit info]</a> <a href=\"change_password.php?requested_id=$attendee_id\">[change password]</a></spon></h1>\n";
	echo "<table>\n";
	echo "<tr>\n";
	echo "<td>Attendee ID: $attendee_id</td>\n";
	echo "<td>Total Cost: $$amount_owed";
	echo "</td>\n</tr>\n<tr>\n<td>";
	echo "Username: $username<br />\n";
	echo "</td>\n<td>";
	echo "Amount Paid: $$amount_paid\n";
	echo "</td>\n</tr>\n<tr>\n<td>";
	echo "E-mail address: <a href=\"mailto:$email_addr\">$email_addr</a><br />\n";
	echo "</td>\n<td>";
	echo "Balance Owed: $$balance<br />\n";
	echo "</td>\n</tr>\n<tr>\n<td>";
	echo "$street_address<br />$city, $state $zip";
	echo "</td>\n<td>";
	if ($_SESSION['admin'] == 't') print_payment_process_form();
	echo "</td>\n</tr>\n<tr>\n<td>";
	if (!empty($organization)) echo "Organization: $organization\n";
	echo "</td>\n<td>";
	echo "$checked_in";
	echo "</td>\n</tr>\n";
	echo "</table>\n";
	echo "<br /><p><span class=\"tiny\">";
	echo "<strong>Created</strong> ".date('m-d-Y g:ia',$createdepoch)." ";
	if (!empty($last_loginepoch)) echo "<strong>Last Logged In</strong> ".date('m-d-Y g:ia',$last_loginepoch)." ";
	if (!empty($modifiedepoch)) echo "<strong>modified</strong> ".date('m-d-Y g:ia',$modifiedepoch)."\n";
	echo "</span></p>";

}

function print_attendee_table($array) {
  //This function takes as input an array of attendee_ids and formats the output as a table.
	if ($_GET['sortdir'] == ASC) $sortdir = DESC;
	else $sortdir = ASC;
	$page = $_SERVER['PHP_SELF'];
	if (isset($_GET['search_key'])) $searchstring = 'search_key='.$_GET['search_key'].'&search_string='.$_GET['search_string'].'&';
	if (isset($_POST['search_key'])) $searchstring = 'search_key='.$_POST['search_key'].'&search_string='.$_POST['search_string'].'&';
	echo "<table>\n";
	echo "	<tr class=\"grey_back\">\n";
	echo "		<th class=\"eventlist\"><strong><a href=\"$page?$searchstring"."sortkey=attendee_id&sortdir=$sortdir\">ID #</a></strong></th>\n";
	echo "		<th class=\"eventlist\"><strong><a href=\"$page?$searchstring"."sortkey=first_name&sortdir=$sortdir\">First </a>Name <a href=\"$page?$searchstring"."sortkey=last_name&sortdir=$sortdir\">Last </a></strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Amount<br />Owed</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong><a href=\"$page?$searchstring"."sortkey=amount_paid&sortdir=$sortdir\">Amount<br />Paid</a></strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Balance</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Address<br /><a href=\"$page?$searchstring"."sortkey=city&sortdir=$sortdir\">City</a>, <a href=\"$page?$searchstring"."sortkey=state&sortdir=$sortdir\">State</a> <a href=\"$page?$searchstring"."sortkey=zip&sortdir=$sortdir\">Zip</a></strong></th>\n";
	echo "		<th class=\"eventlist\"><Strong>Created</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Last Login</strong></th>\n";
	echo "	</tr>\n";
	$i = 0;
	foreach ($array as $row) {
//		$values = get_user_info($row['attendee_id']);
		extract($row);
		$attendee_amount_owed = get_attendee_amount_owed($attendee_id);
		$attendee_amount_paid = get_attendee_amount_paid($attendee_id);
		$balance = $attendee_amount_owed - $attendee_amount_paid;
		echo "	<tr$greyback>\n";
		  echo "		<td class=\"eventlist\">$attendee_id</td>\n";
		  echo "		<td class=\"eventlist\"><a href=\"attendee_home.php?attendee_id=$attendee_id\">$first_name $last_name</a></td>\n";
		  echo "		<td class=\"eventlist\">$attendee_amount_owed</td>\n";
		  echo "		<td class=\"eventlist\">$attendee_amount_paid</td>\n";
		  echo "		<td class=\"eventlist\">$balance</td>\n";
		  echo "		<td class=\"eventlist\">$address1";
		  if (!empty($address2)) echo "<br />$address2";
		  echo "<br />$city, $state $zip";
		  echo "</td>\n";
		  if (!empty($createdepoch)){
		  echo "		<td class=\"eventlist\">".date('m-d-Y',$createdepoch)."</td>\n";} else {
			echo "		<td class=\"eventlist\">Never</td>\n";
			}
		  if (!empty($last_loginepoch)) {
			echo "		<td class=\"eventlist\">".date('m-d-Y',$last_loginepoch)."</td>\n";
			} else {
			echo "		<td class=\"eventlist\">Never</td>\n";
			}
		echo "	</tr>\n";
		if (oddeven($i) == 'even') $greyback = " class=\"grey_back\"";
		if (oddeven($i) == 'odd') $greyback = "";
		unset($attendee_amount_owed, $attendee_amount_paid, $balance);
		$i++;
		}
	echo "</table>";
}

function print_hidden_form_fields($array) {
//takes an array and prints a hidden form field for each value with its key as the name and its value as the value.
	while ($element = each($array)) {
		echo '<input type="hidden" name="'.$element['key'].'" value="'.htmlspecialchars(stripslashes($element['value'])).'">';
		echo "\n";
		}
}

function print_special_cost_form($array) {
	echo "<form method=post action=\"".$_SERVER['PHP_SELF']."\">\n";
	if (empty($values['reg_cost'])) echo "You must specify the amount to charge this person for their special convention registration<br /><br />\n";
	if (!empty($values['reg_cost'])) echo "Do you want to keep their special convention cost the same?<br /><br />\n";
	echo "Special Cost:<span class=\"redtext\">*</span>:\n";
	echo '<input type="hidden" name="special_entered" value="Y">';
    echo "<input type=text name=reg_cost size=6 maxlength=8>\n";
	print_hidden_form_fields($array);
	echo "<input type=submit value=\"Process\">\n</form>";
}

function print_payment_process_form() {
	echo "<form method=post action=\"process_payment.php\">\n";
	echo "Amount received:\n";
    echo "<input type=text name=amount size=6 maxlength=9><br />\n";
?>  Payment Type: <select name="type">
    	<option value="" selected></option>
    	<option value="cash">Cash</option>
    	<option value="check">Check</option>
    	<option value="con credit">Con Credit</option>
    	<option value="credit card">Credit Card</option>
    	<option value="debit card">Debit Card</option>
    	<option value="money order">Money Order</option>
    	<option value="paypal">PayPal</option>
    	<option value="unycoin">UNY-Coin</option>
    </select>
<?
//	echo '<input type="hidden" name="entered_by" value="'.$_SESSION['attendee_id'].'">';
//	echo '<input type="hidden" name="for_attendee_id" value="'.$_SESSION['current_attendee_id'].'">';
	echo "<input type=submit value=\"Process\">\n</form>";
}

function print_cogm_search_form($status) {
	echo "<form method=get action=\"manage_gms.php\">\n";
	echo "Show all Co-GMs whose status is:\n";
?>  <select name="status">
    	<option value="approved" <? if ($status == 'approved') echo 'selected';?>>Approved</option>
    	<option value="all" <? if ($status == 'all' || empty($status)) echo 'selected';?>>Any</option>
    	<option value="denied" <? if ($status == 'denied') echo 'selected';?>>Denied</option>
    	<option value="unapproved" <? if ($status == 'unapproved') echo 'selected' ; ?>> Unapproved</option>
    </select>
<?
	echo "<input type=submit name=\"Search\" value=\"search\">\n</form>";
}

function print_event_search_form() {
	echo "<form method=\"post\" action=\"event_list.php\">\n";
?><select name="search_key">
    	<option value="event_time.start_time" selected>Starting Time</option>
    	<option value="event.event_id">Event id</option>
    	<option value="event.event_title">Event Title</option>
    	<option value="event.event_type">Event Type</option>
    	<option value="event.game_system">Game System</option>
		<?// if ($_SESSION['admin'] = 't') echo "<option value=\"event.approved\">Approved</option>" ;?>
    </select>
<?
	echo "= <input type=\"text\" name=\"search_string\" size=\"15\" maxlength=\"50\">\n";
	echo "<input type=\"submit\" value=\"Search\">\n</form>";

}

function print_timeslot_search_form() {
	echo "<form method=\"post\" action=\"assign_rooms.php\">\n";
?><select name="search_key">
    	<option value="event_time.start_time" selected>Starting Timeslot</option>
		<?// if ($_SESSION['admin'] = 't') echo "<option value=\"event.approved\">Approved</option>" ;?>
    </select>
<?
	echo "= <input type=\"text\" name=\"search_string\" size=\"15\" maxlength=\"50\">\n";
	echo "<input type=\"submit\" value=\"Search\">\n</form>";

}

function print_attendee_search_form() {
	echo "<form method=get action=\"attendee_search_results.php\">\n";
?><select name="search_key">
    	<option value="attendee_id" selected>Attendee id</option>
    	<option value="first_name">First name</option>
    	<option value="last_name">Last Name</option>
    	<option value="city">City</option>
    	<option value="email_addr">E-mail address</option>
    	<option value="state">State</option>
    	<option value="organization">Organization</option>
    </select>
<?
	echo "= <input type=\"text\" name=\"search_string\" size=\"15\" maxlength=\"50\">\n";
	echo "<input type=\"submit\" value=\"Search\">\n</form>";

}

function print_modify_status_form($values) {
	echo "<form method=post action=\"".$_SERVER['PHP_SELF']."\">\n";
?>
Registration Day:
<select name="event_day">
          <option value="all week-end" <? if ($values['event_day'] == 'all week-end' || $values['event_day'] == '') {echo 'Selected'; }?>>All week-end</option>
          <option value="friday" <? if ($values['event_day'] == 'friday') {echo 'Selected'; }?>>Friday</option>
          <option value="saturday" <? if ($values['event_day'] == 'saturday') {echo 'Selected'; }?>>Saturday</option>
          <option value="sunday" <? if ($values['event_day'] == 'sunday') {echo 'Selected'; }?>>Sunday</option>
        </select><br />
Registration Type:
<select name="reg_type">
          <option value="" <? if ($values['reg_type'] == '') {echo 'selected'; }?>></option>
          <option value="general admit on-site" <? if ($values['reg_type'] == 'general admit on-site') {echo 'selected'; }?>>General Admittance On-Site</option>
          <option value="general admit coupon" <? if ($values['reg_type'] == 'general admit coupon') {echo 'selected'; }?>>General Admittance With Coupon</option>
          <option value="general admit pre-reg" <? if ($values['reg_type'] == 'general admit pre-reg') {echo 'selected'; }?>>General Admittance Pre-reg</option>
          <option value="gm" <? if ($values['reg_type'] == 'gm') {echo 'selected'; }?>>Game Master (4 events)</option>
          <option value="gm only" <? if ($values['reg_type'] == 'gm only') {echo 'selected'; }?>>Game Master Only</option>
          <option value="exhibitor" <? if ($values['reg_type'] == 'exhibitor') {echo 'selected'; }?>>Exhibitor</option>
         <option value="additional exhibitor" <? if ($values['reg_type'] == 'additional exhibitor') {echo 'selected'; }?>>Additional Exhibitor</option>
          <option value="LARP only" <? if ($values['reg_type'] == 'LARP only') {echo 'selected'; }?>>MET LARP Only</option>
          <option value="special guest" <? if ($values['reg_type'] == 'special guest') {echo 'selected'; }?>>Special Guest</option>
          <option value="staff" <? if ($values['reg_type'] == 'staff') {echo 'selected'; }?>>Staff</option>
          <option value="special" <? if ($values['reg_type'] == 'special') {echo 'selected'; }?>>Special</option>
          <option value="volunteer" <? if ($values['reg_type'] == 'volunteer') {echo 'selected'; }?>>Volunteer</option>
        </select><br />
Registration Status:
<select name="reg_status">
          <option value="" <? if ($values['reg_status'] == '') {echo 'selected'; }?>></option>
          <option value="pending" <? if ($values['reg_status'] == 'pending') {echo 'selected'; }?>>Pending</option>
          <option value="approved" <? if ($values['reg_status'] == 'approved') {echo 'selected'; }?>>Approved</option>
        </select><br />
Update event status to above value: <input type=checkbox name="approve_events" value="Y">
<?
	echo '<br />Current Cost of Registration is '.$values['cost'].'<br />';
	echo '<input type="hidden" name="for_attendee_id" value="'.$values['attendee_id'].'"><br />';
	echo "<input type=submit value=\"Process\">\n</form>";
}

function print_ts_links($text, $page, $min, $max, $printzero) {
	//This function could be cool it prints links to the timeslots with text of $text and to the page denoted by $page. It prints the links between $min and $max. Optionally it can print the ts 0 link.
	if ($printzero = 'printts0') echo "<li class=\"inline-list\"><a href=\"http://loki.local/~plummer/uny-con/registration/$page&TS=0\">[".$text."0]</a></li>\n";
	for ( ;$min <= $max ; $min++) {
		   echo "<li class=\"inline-list\"><a href=\"http://loki.local/~plummer/uny-con/registration/$page&TS=$min\">[$text$min]</a></li>\n";
       		}
}

function print_event_id_menu($timeslot, $reg_attendee_id, $count) {
	//this function will take an array of timeslots and events and build a select menu out of it.
	$select_option = "\n<select name=\"reg_item[$count]\">";
	$result = get_event_list_for_signup("$timeslot", "all", "", "event_id", "ASC");
	$event_array=db_result_to_array($result);
	$select_option .= "\n<option value=\"\">Timeslot $timeslot</option>\n";
	foreach ($event_array as $row) {
		$currplayers = get_current_num_players($row['event_id'], $row['start_time']);
		$select_option .= "<option value=\"$reg_attendee_id.$timeslot.".$row['event_id']."\"";
		$select_option .= ">";
		$select_option .= "TS$timeslot".$row['event_id']." $currplayers/".$row['max_players']."";
		if ($row['max_players'] <= $currplayers) $select_option .= " FULL";
		$select_option .= "</option>\n";
		}
	$select_option .= "</select>\n";
	return $select_option;
}

function print_short_description($event_pgresult) {
	//This function will take an array of input events and format them in a condensed format. Showing the event title, description and GM/Sponsor and when it is available.
	//needs to truncate descriptions and not repeat events in multiple time slots but maybe just print what time slots he event is availbale in. perhaps we should print them by category also...
	if (pg_numrows($event_pgresult) == 0) return false ;
	$num = pg_numrows($event_pgresult);
	$i=0;
	while ($i < $num) {
		$values = recordproc($event_pgresult, $i);
		extract($values);
		echo "<h2>".htmlentities($event_title)."</h2>\n";
		echo "<strong>Event Type:</strong> $event_type<br />\n";
		echo "<strong>Run By:</strong> $name<br />\n";
		echo "<p>".htmlentities(html_substr($description, 150, 10))."<a href=\"http://loki.local/~plummer/uny-con/registration/eventdetails.php?searchtype=eventid&searchterm=$event_id\">Read More</a></p>\n";
		$i++;
	}
}

function print_coupon_form($values = '') {
// This function prints a form for entering coupons.
	?>
	<form method="post" action="manage_coupons.php">
	Description: <input type="text" name="description" size="25" maxlength="50" value="<?if (isset($values['description'])) echo $values['description'] ; ?>"><br />
	Amount of Coupon:<input type="text" name="amount" size="6" maxlength="6" value="<?if (isset($values['amount'])) echo $values['amount'] ; ?>"><br />
	Coupon Code: <?echo "$coupon_code" ; ?><input type="hidden" name="coupon_code" value="<?if (isset($values['coupon_code'])) echo $values['coupon_code'] ; ?>"><br />
	Active? <input type="checkbox" name="active" value="t" <?if ($values['active'] == 't' || !isset($values['active'])) echo 'checked' ; ?>><br /><br />
	<?
	if (isset($values['coupon_id'])) {
	?>
	<input type="hidden" name="coupon_id" value="<? echo $values['coupon_id'] ; ?>">
	<?
	}
	?>
	<input type="submit" name="submit" value="Submit"><input type="submit" name="cancel" value="Cancel">
	</form>


	<?
}


function do_news_update($item, $cat, $title)
{
	$conn = db_connect();
	If(isset($_POST) && !empty($_POST))
	{
	$id = $_SESSION['attendee_id'];
	$query = "INSERT INTO news (item, item_category, item_title, create_date, create_by, last_update_date, last_update_by) VALUES ('$item', '$cat', '$title', 'now()', '$id', 'now()', '$id')";
	$new_news = pg_query("$query");
	echo "Your Post has been successfully uploaded.";
	};
	echo "<form action=\"".$_SERVER['PHP_SELF']."\"method=\"post\">";
	echo "<p>Category:</p><select id=\"cat\">";
	echo "<option>Special Guest</option>";
	echo "<option>Housing</option>";
	echo "<option>Event Information</option>";
	echo "</select>";
	echo "<p>Title:</p><textarea name=\"title\" cols=\"43\" rows=\"2\"></textarea>";
	echo "<p>News Item:</p><textarea name=\"news\" cols=\"43\" rows=\"16px\">";
	echo "</textarea>";
	echo "<input type=submit value=\"Add News Item\">";
	echo "</form>";
}

function display_allnews_items()
{
	$conn = db_connect();
	$query = "SELECT * FROM news ORDER BY create_date DESC";
	$result = pg_query($query);
	$result2 = pg_query("SELECT news.*, EXTRACT(EPOCH FROM news.create_date) as create_dateepoch");
	$final = pg_num_rows($result);
	if($final == 0) {echo "<p>No News is bad news</p>";}
	else {
	for ( $i = 0; $i < $final ; $i++)
	{
		$newsitem = pg_fetch_array($result, $i, PGSQL_ASSOC);
		$timestamp = pg_fetch_array($result2, $i, PGSQL_ASSOC);
		$time = $timestamp['create_dateepoch'];
		$time = date('m-d-y g:i a',$time);
		$news = $newsitem['item'];
		$id = $newsitem['last_update_by'];
		$title = $newsitem['item_title'];
		$user = pg_query("SELECT username FROM attendee WHERE attendee_id = $id");
		$user = pg_fetch_array($user, 0, PGSQL_ASSOC);
		$username = $user['username'];
		if(check_valid_user() && $_SESSION['admin'] == 't') {echo "<p><span class=\"newsitem\"><strong>$title</strong></span><span class=\"submitinfo\"> $username at";}
		else  echo "<p><span class=\"newsitem\"><strong>$title</strong></span><span class=\"submitinfo\">";
		echo " $time </span></p>";
		echo "<br><p class=\"newsbox\">$news</p>";
		echo "<br>";
	}
	};
	
}

function display_latestnews_items()
{
	$conn = db_connect();
	$query = "SELECT * FROM news ORDER BY create_date DESC";
	$result = pg_query($query);
	$result2 = pg_query("SELECT news.*, EXTRACT(EPOCH FROM news.create_date) as create_dateepoch");
	$empty = pg_num_rows($result);
	if($empty == 0) { echo "<p>No News is Bad News</p>"; }
	else
	{
		$newsitem = pg_fetch_array($result, 0, PGSQL_ASSOC);
		$timestamp = pg_fetch_array($result2, 0, PGSQL_ASSOC);
		$time = $timestamp['create_dateepoch'];
		$time = date('m-d-y g:i a',$time);
		$news = $newsitem['item'];
		echo "<p><strong>$time</strong></p>";
		echo "<p>$news</p>";
	};
}
/**
* Print start time list based off of hours of the convention
*
* Currently Selects manually defined dates, should query the database for the date information in the future.  Sets and opt group for each date, and then displays the hours available in that date as a starting time.  Hours in the day will also be hard coded initially but should be fed in the future from the convention hours table.
*/

function query_con_hours()
{
	if (!($conn = db_connect()))
		return false;
	$query = "SELECT * FROM con_hours ORDER BY day";
	$result = pg_query($query);
	return $result;
}

function print_starting_time_list($time_selected = "")
{
	//get each day the convention runs from db.
	$result = query_con_hours();
	$num_results = pg_num_rows($result);
	for($a=0;$a<$num_results;$a++)
	{
			$day = pg_fetch_array($result, $a);
			$date = $day['day'];
			
			if(empty($day['start_time'])) 
				{ $day['start_time'] = "$date 00:00:00-05"; }
			$start_epoch=strtotime($day['start_time']);
			$start = date(H, $start_epoch);
			
			if(empty($day['end_time'])) 
				{ $day['end_time'] = "$date 23:00:00-05"; }
			$end_epoch=strtotime($day['end_time']);
			$end = date(H, $end_epoch);
			
			if($end == "00") { $end = "23"; }
			$name = $day['code'];
			echo "<optgroup label=\"$name $date\">\n";
			for($i=$start;$i<=$end;$i++)
			{
				if($i<13) { $j = $i; }
				else { $j = $i-12; }
				$k = $i;
				if($j == "0") { $j = "12"; }
				$timestamp = "".$date." ".$i.":00:00";
				echo "\t\t<option value=\"$timestamp\"";
				if($time_selected == $timestamp) 
					{ echo ' selected="selected"'; }
				echo ">$name ".$j.":00";
				if($i<12) { echo "am"; }
				else { echo "pm"; }
				echo "</option>\n";
			}
	}
}

function print_badge_entry_form($values = '') {
// This function prints a form for entering con badges.
	?>
	<h2>Badge Entry Form</h2><br />
	<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
	Badge Type: <input type="text" name="badge_type" size="25" maxlength="50" value="<?if (isset($values['badge_type'])) echo htmlspecialchars(stripslashes($values['badge_type'])) ; ?>"><span class="grey_text">This is the text that shows in drop down menus</span><br />
	Description: <input type="text" name="description" size="25" maxlength="50" value="<?if (isset($values['description'])) echo htmlspecialchars(stripslashes($values['description'])) ; ?>"><br />
	Cost of Badge:<input type="text" name="amount" size="6" maxlength="6" value="<?if (isset($values['amount'])) echo float($values['amount']) ; ?>"><span class="grey_text">0.00</span><br />
	User Selectable? <input type="checkbox" name="user_available" value="t" <?if ($values['user_available'] == 't' || !isset($values['user_available'])) echo 'checked' ; ?>><span class="grey_text">Should normal users be allowed to select this badge type</span><br /><br />
	<?
	if (isset($values['badge_type_id'])) {
	?>
	<input type="hidden" name="badge_type_id" value="<? echo $values['badge_type_id'] ; ?>">
	<?
	}
	?>
	<input type="submit" name="submit" value="Submit"><input type="submit" name="cancel" value="Cancel">
	</form>


	<?
}

function print_badge_list() {
?>
	<h2>Badge Types</h2><br />
	<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
	<table>
	<tr class="grey_back">
		<th class=\"eventlist\"><strong>Badge Type</strong></th>
		<th class=\"eventlist\"><strong>Cost</strong></th>
		<th class=\"eventlist\"><strong>User Avail</strong></th>
		<th class=\"eventlist\"><strong>Description</strong></th>
		<th class=\"eventlist\"></th>
	</tr>
<?
	$result = get_badge_types();
	if (pg_numrows($result) == 0) ;
	$num = pg_numrows($result);
	$i=0;
	while ($i < $num) {
		$values = pg_fetch_array($result, $i, PGSQL_ASSOC) ;
		if($values['user_available'] = 't') $useravailable = 'Yes';
		if($values['user_available'] = 'f') $useravailable = 'No';
		echo "<tr$silverback>";
		echo "<td class=\"eventlist\">".$values['badge_type']."</td>";
		echo "<td class=\"eventlist\">".$values['cost']."</td>";
		echo "<td class=\"eventlist\">".$useravailable."</td>";
		echo "<td class=\"eventlist\">".$values['description']."</td>";
		echo "<td class=\"eventlist\"><input name=\"edit\" id=\"badge_id\" type=\"radio\" value=\"".$values['badge_type_id']."\" /></td>";
		echo "</tr>";
		if (oddeven($i) == 'even') $silverback = " class=\"silver_back\"";
		if (oddeven($i) == 'odd') $silverback = "";
		++$i;
		}
	echo '</table>';
	?>
	<input type="submit" name="edit" value="Edit Selected">
	<?
}
function print_discount_form($formsent, $values, $gen_discount)
{
if (isset($values)) { extract($values); }
if (isset($gen_discount)) 
	{  
		echo "<span class=\"bold\">Discount Generated!</span><br>";
		insert_discount_info($values);
		unset($unlimited);
		unset($description);
		unset($discount_amount);
		unset($kickback_amount);
		unset($expire_date);
		unset($num_of_uses);
	}
if (isset($formsent))  {
	$code = generate_coupon_code_unique($prefix, $code);
} // close formsent

?>	<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
	<table class="discountform">
		<tr><td colspan="2"><h2>Discount Generation Form</h2></td></tr>
		<tr><td>Description:</td><td><input name="description" type="text" size="50" maxlength="50"<?
		if(isset($description)) { echo "value=\"$description\"";}
		?>></td></tr>
		<tr><td>Code Prefix:</td><td><input name="prefix" type="text" size="10" maxlength="3"<?
		if(isset($prefix)) { echo "value=\"$prefix\"";}
		?>><span class="grey_text">UNY</span></td></tr>
		<tr><td>Discount Amount:</td><td>$<input name="discount_amount" type="text" size="10" maxlength="9"<?
		if(isset($discount_amount)) { echo "value=\"$discount_amount\"";}
		?>><span class="grey_text">0.00</span></td></tr>
		<tr><td>Kickback Amount:</td><td>$<input name="kickback_amount" type="text" size="10" maxlength="9"<?
		if(isset($kickback_amount)) { echo "value=\"$kickback_amount\"";}
		?>><span class="grey_text">0.00</span></td></tr>
		<tr><td>Expiration Date:</td><td><input name="expire_date" type="text" size="10" maxlength="10"<?
		if(isset($expire_date)) { echo "value=\"$expire_date\"";}
		?>><span class="grey_text">2005/01/01</span></td></tr>
		<tr><td>Number of uses:</td><td><input name="num_of_uses" type="text" size="10" maxlength="3"<?
		if((isset($num_of_uses))&&(($unlimited!=="t"))) { echo "value=\"$num_of_uses\"";}
		?>><input name="unlimited" type="checkbox" value="t"<?
		if($unlimited=="t") { echo "checked"; }
		?>>Check for Unlimited</td></tr>
		<tr><td>Coupon Code:</td><td>
		<? if(isset($code)) 
		{ 
			echo '<span class="greentext">';
			echo "$code"; 
			echo '<input type="hidden" name="coupon_code" value="'.$code.'">';
		} 
		else { echo '<span class="grey_text">'; echo "unset"; }
		?></span></td></tr>
	</table>
	<br>
	<input type="hidden" name="formsent" value="true">
	<? if(isset($formsent)) {
	echo '<input type="submit" name="submit" value="Regenerate Discount Code">';
	}
		else {
	echo '<input type="submit" name="submit" value="Generate Discount Code">';
	}
	?>
</form>  
<?
	if((isset($code))&&(isset($formsent))) {
		echo '<form action="';
		echo $_SERVER['REQUEST_URI'];
		echo '" method="post">';
		foreach($values as $name => $value)
		{
		if($name == "coupon_code") { $value = $code; }
		echo '<input type="hidden" name="'.$name.'" value="'.$value.'">';
		}
		echo '<input type="hidden" name="gen_discount">';
		echo '<input type="submit" name="submit" value="Approve Code"></form>';
	}

} //Close print_discount_form

function print_merchant_request_form()
{

if(isset($_POST['formsent']))
{
	$user = $_SESSION['username'];
	$UCuser = ucwords($user);
	$request = $_POST['request'];
	echo "<p>$UCuser your request has been submitted!  If the request falls within the range of goods that our exhibitors provide we will request that they stock the item before attending.  Thank you for helping us let our exhibitors meet your needs!</p>";
}

?>
	<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
	<table class="discountform">
		<tr><td colspan="2"><h2>Request for merchandise</h2></td></tr>
		<tr><td>
			Briefly name or describe the product you are looking for:
		</td></tr>
		<tr><td>
			<textarea name="request" rows="10" cols="40">
</textarea>
		</td></tr>
	</table>
	<input name="formsent" type="hidden" />
	<input type="submit" value="Submit" />
	</form>
<?
}

function print_event_request_form()
{

if(isset($_POST['formsent']))
{
	$user = $_SESSION['username'];
	$UCuser = ucwords($user);
	$system = $_POST['system'];
	$version = $_POST['version'];
	echo "<p>$UCuser your request for $system version $version has been submitted!  We hope to be able to encourage GMs to ensure that a session of this event runs if there are enough of your fellow players to fill a table.</p>";
}

?>
	<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
	<table class="discountform">
		<tr><td colspan="2"><h2>Request for Game System</h2></td></tr>
		<tr>
			<td>List the system you would like to play:</td>
			<td>
			<input name="system" type="text" size="16" maxlength="30" />
			</td>
		</tr>
		<tr>
			<td>List the version you would like to play:</td>
			<td>
			<input name="version" type="text" size="16" maxlength="30" />
			</td>
		</tr>
	</table>
	<input name="formsent" type="hidden" />
	<input type="submit" value="Submit" />
	</form>
<?

}

?>